package text111;

public class Solution38 {
	static int p = 0;
    public boolean isBalanced(TreeNode root) {
    	if (root==null) {
			return true;
		}
    	res(root);
        System.out.println(p);
    	if (p == 0) {
			return true;
		}else {
			return false;
		}	
    }
    public void res(TreeNode root) {
    	if (root==null) {
			return ;
		}
    	int t = Math.abs(funMax(root.left)-funMax(root.right));
            	System.out.println(t);
    	if(t>1) {
    		p = 1;
    	}
    	res(root.left);
    	res(root.right);	
	}
    //树的深度
    public int funMax(TreeNode root) {
    	if (root==null) {
			return 0;
		}
		int lenth = 1 + Math.max(funMax(root.left), funMax(root.right));
		return lenth;
	}
	/*
	 * if (root == null) return true; return Math.abs(depth(root.left) -
	 * depth(root.right)) <= 1 && isBalanced(root.left) && isBalanced(root.right); }
	 * 
	 * private int depth(TreeNode root) { if (root == null) return 0; return
	 * Math.max(depth(root.left), depth(root.right)) + 1; }
	 */
}
